Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SM-386 #185

Merged
merged 3 commits into from
Aug 6, 2024
Merged

SM-386 #185

merged 3 commits into from
Aug 6, 2024

Conversation

JCSanPedro
Copy link
Collaborator

This is a small PR that adds the following methods to the RewardsManager contract.

  • getClaim
  • getUnclaimedReward
  • getUnclaimedReward

These methods make it easier for clients to determine if a user has an unclaimed reward for a given cycle.

Copy link
Contributor

@Nick95550 Nick95550 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good only minors

Comment on lines 134 to 155

function getUnclaimedReward(address node, address user, uint256 cycle) external view returns (uint256) {
return _getUnclaimedReward(node, user, cycle);
}

function _getUnclaimedReward(address node, address user, uint256 cycle) internal view returns (uint256) {
if (claims[node][user][cycle]) {
return 0;
}

return _getClaim(node, user, cycle);
}

function getUnclaimedRewards(address node, address user, uint256[] calldata cycles) external view returns (uint256[] memory) {
uint256 [] memory unclaimedRewards = new uint256[](cycles.length);

for (uint256 i = 0; i < cycles.length; i++) {
unclaimedRewards[i] = _getUnclaimedReward(node, user, cycles[i]);
}

return unclaimedRewards;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:

Suggested change
function getUnclaimedReward(address node, address user, uint256 cycle) external view returns (uint256) {
return _getUnclaimedReward(node, user, cycle);
}
function _getUnclaimedReward(address node, address user, uint256 cycle) internal view returns (uint256) {
if (claims[node][user][cycle]) {
return 0;
}
return _getClaim(node, user, cycle);
}
function getUnclaimedRewards(address node, address user, uint256[] calldata cycles) external view returns (uint256[] memory) {
uint256 [] memory unclaimedRewards = new uint256[](cycles.length);
for (uint256 i = 0; i < cycles.length; i++) {
unclaimedRewards[i] = _getUnclaimedReward(node, user, cycles[i]);
}
return unclaimedRewards;
}
function getUnclaimedReward(address node, address user, uint256 cycle) external view returns (uint256) {
return _getUnclaimedReward(node, user, cycle);
}
function getUnclaimedRewards(address node, address user, uint256[] calldata cycles) external view returns (uint256[] memory) {
uint256 [] memory unclaimedRewards = new uint256[](cycles.length);
for (uint256 i = 0; i < cycles.length; i++) {
unclaimedRewards[i] = _getUnclaimedReward(node, user, cycles[i]);
}
return unclaimedRewards;
}
function _getUnclaimedReward(address node, address user, uint256 cycle) internal view returns (uint256) {
if (claims[node][user][cycle]) {
return 0;
}
return _getClaim(node, user, cycle);
}

);

for (const [i, r] of unclaimedRewards.entries()) {
expect(r).to.be.eq(BigInt(i + 1) * rewardAmount);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:

Suggested change
expect(r).to.be.eq(BigInt(i + 1) * rewardAmount);
expect(r).to.be.equal(BigInt(i + 1) * rewardAmount);

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think .eq is not ambiguous at all

Copy link
Contributor

@Nick95550 Nick95550 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Nick95550 Nick95550 merged commit c6b1957 into v2/seeker-staking Aug 6, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants